package entity;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "Catalog")
@Entity
@Table(name="t_catalog")
public class Catalog extends AbstractEntity{

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="catalog_id")
	private Long id;
	
	@Column(name="catalog_name")
	private String name;

	@Column(name="catalog_type")
	private Integer type;
	
	@Transient
	private Collection<Case> cases ;
	
	@Override
	public void acceptValue(AbstractEntity input) {
		if(input!=null && input instanceof Catalog){
			Catalog catalog=(Catalog)input;
			this.setName(catalog.getName());
		}
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	
	
	@Override
	public Long getKey() {
		return id;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	
	


	
	//@OneToMany(targetEntity=Case.class,cascade= {CascadeType.ALL},fetch=FetchType.LAZY)

	public Collection<Case> getCases() {
		return cases;
	}
	public void setCases(Collection<Case> cases) {
		this.cases = cases;
	}
	public Map<String, String> toValueMap(){
		Map<String, String> values=new HashMap<String, String>();
//		Class cls=Catalog.class;
//		Field fs=cls.getDeclaredFields();
		
		values.put("id", ""+this.getId());
		values.put("name", ""+this.getName());
		return values;
	}
}
